<%@ include file="/webapis/ui/doctype.jspf" %>

<%@ taglib uri="/bbNG" prefix="bbNG"%>
<%@ taglib uri="/bbData" prefix="bbData"%>
<%@ taglib prefix='c' uri="http://java.sun.com/jsp/jstl/core" %>  
<%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %> 

<script src="../dist/js/jquery-3.1.1.min.js" type="text/javascript"></script>

<fmt:setLocale value="${locale}"/> 
<fmt:bundle basename="messages"/>
<bbNG:genericPage>

<bbNG:jsBlock>
<script type="text/javascript">
jQuery.noConflict();
function searchByCondition(){
	
    var oper = document.getElementById("_searchOper").value;
    var attr = document.getElementById("_searchKey").value;
    var value = document.getElementById("_searchValue").value;
    var isImported = document.getElementById("_searchType").value;
    var param = {
        "attrStr" : attr,
        "operStr" : oper,
        "value" : value,
        "isExported" : "",
        "isImported" : isImported
    };    
    
    var oper = document.getElementById("_searchOper1").value;
    var attr = document.getElementById("_searchKey1").value;
    var value = document.getElementById("_searchValue1").value;
    var extendOper = document.getElementById("_logical1").value;
    var param1 = {
            "attrStr" : attr,
            "operStr" : oper,
            "value" : value,
            "extendOperstr" : extendOper
    };
    
    var oper = document.getElementById("_searchOper2").value;
    var attr = document.getElementById("_searchKey2").value;
    var value = document.getElementById("_searchValue2").value;
    var extendOper = document.getElementById("_logical2").value;
    var param2 = {
            "attrStr" : attr,
            "operStr" : oper,
            "value" : value,
            "extendOperstr" : extendOper
    };
  
    var list = '['+JSON.stringify(param);
    if(jQuery("#extention1").css('display') == 'block')
    	list+=","+JSON.stringify(param1);
    if(jQuery("#extention2").css('display') == 'block')
    	list+=","+JSON.stringify(param2);
    list+=']';
    jQuery("#condition").val(list);
    jQuery("#searchImportCourseInfoForm").submit();   
}

function importCourse(){
	validateImport();
}

function validateImport(){
	var ckboxs = document.getElementsByName("ckbox");
	var listForm = jQuery("#listForm");
	
	//---variable need to append to json	
	var courseIdList = document.getElementsByName("courseIdValue");
	var arr = new Array();
	for(var i = 0; i < ckboxs.length; i++){
		if (ckboxs[i].checked){
			arr.push(courseIdList[i].value);
		}
	}
	var data = JSON.stringify(arr);
    jQuery.ajax({
    	async: false,
        url: "../course/importCourse",    
        contentType:"application/json",   
        dataType: "text",
        type: "POST",
        data:data,     
        success: function (result) {
           alert(result);
    },
       error: function (e) {
          alert("failed");
       }
    });  
}

function extend(){
	if(jQuery("#extention1").css('display') == 'none' ){
		jQuery("#extention1").css('display','block'); 
	}
	else if(jQuery("#extention2").css('display') == 'none'){
		jQuery("#extention2").css('display','block'); 
	}
		
}

function reduce(){
	if(jQuery("#extention2").css('display') == 'block' ){
		jQuery("#_searchValue2").val("");
		jQuery("#extention2").css('display','none'); 
	}
	else if(jQuery("#extention1").css('display') == 'block'){
		jQuery("#_searchValue1").val=("");
		jQuery("#extention1").css('display','none'); 
	}		
}

function batchImportCourse(){
	jQuery.ajax({
    	async: false,
        url: "../course/batchImportCourse",    
        contentType:"application/json",   
        dataType: "text",
        type: "POST",
        data:"",     
        success: function (result) {
           alert(result);
    },
       error: function (e) {
          alert("failed");
       }
    });  
}

</script>
</bbNG:jsBlock>

<bbNG:breadcrumbBar  environment="sys_admin" navItem="admin_main">
<fmt:message key="index" var="index"/>
<bbNG:breadcrumb href="../index">index</bbNG:breadcrumb>
</bbNG:breadcrumbBar>

<bbNG:actionControlBar>
<%-- <input type="button" class="genericButton" onclick="importCourse()" value="${title}"/>
 --%>
 
 <fmt:message key="import.course" var="title"/>
 <bbNG:actionButton id="importAction" url="../course/getCourseBycondition" title="${title}" onClick = "importCourse()" primary="true"/>
 <fmt:message key="batchImport.course" var="batchImport"/>
 <bbNG:actionButton id="batchImportAction" url="../course/getCourseBycondition" title="${batchImport}" onClick = "batchImportCourse()" primary="true"/>
<bbNG:actionPanelButton type="SEARCH" alwaysOpen="true">
<br/>
	<FORM id="searchImportCourseInfoForm" method="post" name="searchImportCourseInfoForm" action="../course/getCourseBycondition">
		<input type="hidden" name="actionString" value="Search"/>
  	<div class="groupLabel"><fmt:message key="search"/></div>
  	<div>
		<select id="_searchType" NAME="_searchType">
		  <OPTION VALUE="unimport"><fmt:message key="unimported"/></OPTION>
		  <OPTION VALUE="imported"><fmt:message key="imported"/></OPTION>
		  <OPTION VALUE="all" selected><fmt:message key="all"/></OPTION>
		</select>
		<select id="_searchKey" NAME="_searchKey">
		  <OPTION VALUE="courseId"><fmt:message key="courseId"/></OPTION>
		  <OPTION VALUE="courseName"><fmt:message key="courseName"/></OPTION>
		  <OPTION VALUE="DepartmentID"><fmt:message key="departmentId"/></OPTION>
		</select>
		<select id="_searchOper" NAME="userInfoSearchOperatorString">
			<OPTION VALUE="Contains"><fmt:message key="contains"/></OPTION>
			<OPTION VALUE="Equals"><fmt:message key="equals"/></OPTION>
			<OPTION VALUE="StartWith"><fmt:message key="startwith"/></OPTION>
		</select>
		<INPUT id="_searchValue" TYPE="TEXT" NAME="userInfoSearchText" VALUE="" size="45" maxlength="64"/>
		<input id="condition" name="condition" value="" type="hidden"/>
		<input type="submit" class="genericButton" onclick="searchByCondition()" value="<fmt:message key="execute"/>"/>
		
  	</div>
  </FORM>
</bbNG:actionPanelButton>
</bbNG:actionControlBar>

<div id = extention1 style="display:none">
	<FORM id="searchImportCourseInfoForm1" method="post" name="searchImportCourseInfoForm" action="../course/getCourseBycondition">
  	<div>
  		<select id="_logical1" NAME="_logical">
		  <OPTION VALUE="and"><fmt:message key="and"/></OPTION>
		  <OPTION VALUE="or"><fmt:message key="or"/></OPTION>
		</select>
		<select id="_searchKey1" NAME="_searchKey">
		  <OPTION VALUE="courseId"><fmt:message key="courseId"/></OPTION>
		  <OPTION VALUE="courseName"><fmt:message key="courseName"/></OPTION>
		  <OPTION VALUE="DepartmentID"><fmt:message key="departmentId"/></OPTION>
		</select>
		<select id="_searchOper1" NAME="userInfoSearchOperatorString">
			<OPTION VALUE="Contains"><fmt:message key="contains"/></OPTION>
			<OPTION VALUE="Equals"><fmt:message key="equals"/></OPTION>
			<OPTION VALUE="StartWith"><fmt:message key="startwith"/></OPTION>
		</select>
		<INPUT id="_searchValue1" TYPE="TEXT" NAME="userInfoSearchText" VALUE="" size="45" maxlength="64"/>
		
  	</div>
  </FORM>
</div>

<div id = extention2 style="display:none">
	<FORM id="searchImportCourseInfoForm2" method="post" name="searchImportCourseInfoForm" action="../course/getCourseBycondition">
  	<div>
  		<select id="_logical2" NAME="_logical">
		  <OPTION VALUE="and"><fmt:message key="and"/></OPTION>
		  <OPTION VALUE="or"><fmt:message key="or"/></OPTION>
		</select>
		<select id="_searchKey2" NAME="_searchKey">
		  <OPTION VALUE="courseId"><fmt:message key="courseId"/></OPTION>
		  <OPTION VALUE="courseName"><fmt:message key="courseName"/></OPTION>
		  <OPTION VALUE="DepartmentID"><fmt:message key="departmentId"/></OPTION>
		</select>
		<select id="_searchOper2" NAME="userInfoSearchOperatorString">
			<OPTION VALUE="Contains"><fmt:message key="contains"/></OPTION>
			<OPTION VALUE="Equals"><fmt:message key="equals"/></OPTION>
			<OPTION VALUE="StartWith"><fmt:message key="startwith"/></OPTION>
		</select>
		<INPUT id="_searchValue2" TYPE="TEXT" NAME="userInfoSearchText" VALUE="" size="45" maxlength="64"/>
		
  	</div>
  </FORM>
</div>

<form id = "listForm" action="../course/importCourse">
<bbNG:inventoryList collection="${list}" initialSortCol="userId" objectVar="tmpcourse" className="cn.com.blackboard.DataModule4B2.model.CourseInfo" url="">

<bbNG:listCheckboxElement name="ckbox" value="<%=tmpcourse.getCourseId()%>" showCheckbox="true"/>
<fmt:message key="courseId" var="courseId"/>
<bbNG:listElement label="${courseId}" name="courseId" comparator="${courseidComparator}" isRowHeader="true">
    <%=tmpcourse.getCourseId()%>
	<input TYPE="hidden" NAME="courseIdValue" VALUE="${tmpcourse.getCourseId()}">
</bbNG:listElement>
<fmt:message key="courseName" var="courseName"/>
<bbNG:listElement label="${courseName}" name="courseName" comparator="${getCourseNameComparator}" >
    <%=tmpcourse.getCourseName()%>
	<input TYPE="hidden" NAME="courseNameValue" VALUE="${tmpcourse.getCourseName()}">
</bbNG:listElement>
<fmt:message key="departmentId" var="departmentId"/>
<bbNG:listElement label="${departmentId}" name="departmentId" comparator="${getDepartmentIdComparator}" >
    <%=tmpcourse.getDepartmentId()%>    
	<input TYPE="hidden" NAME="departmentIdValue" VALUE="${tmpcourse.getDepartmentId()}">
</bbNG:listElement>
<fmt:message key="status" var="status"/>
<bbNG:listElement label="${status}" name="isImported">
	<c:if test="${tmpcourse.getIsimported()=='N'}"><fmt:message key="unimported"/></c:if>
	<c:if test="${tmpcourse.getIsimported()=='Y'}"><fmt:message key="imported"/></c:if> 
	<input TYPE="hidden" NAME="isImportedValue" VALUE="${tmpcourse.getIsimported()}">
</bbNG:listElement>

<bbNG:listOptions allowRefresh="true" refreshUrl="javascript:validateRefresh()" allowShowAll="true"/>

</bbNG:inventoryList>
</form>

<fmt:message key="strButOk" var="strButOk"/>
<bbNG:button id = "refreshBtn" type="PageLevel" label="${strButOk}" url="../index"/>



</bbNG:genericPage>


